package com.csg.service.service.impl;

import com.csg.service.entity.Role;
import com.csg.service.entity.User;
import com.csg.service.service.UserService;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * @author george
 */
@Slf4j
@Service(value = "userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) {
        log.info("登录用户的账号：" + username);
        String password = passwordEncoder.encode("123456");
        log.info("登录用户的密码：" + password);
        Set<Role> roles = Sets.newHashSet();
        roles.add(new Role("ROLE_USER"));
        return new User(password, username, roles);
    }
}
